//version: 1.0.1 
package testcase;

import roster.*;
import junit.framework.TestCase;

public class TestController extends TestCase{
	public static Schedule x;
	public int noOfRecords=5;
	public String name="test";
	public int date=19022013;
	public String[] staffName={"Eva", "Coach", "Yanis", "Peter", "Marry"};
	public String[][] time={{"ABC", "BC", "AC", "B", "C", "-", "-"},
							{"ABC", "BC", "AC", "B", "C", "-", "-"},
							{"ABC", "BC", "AC", "B", "C", "-", "-"},
							{"ABC", "BC", "AC", "B", "C", "-", "-"},
							{"ABC", "BC", "-", "-", "-", "-", "-"}};
	
	public void setUp() throws Exception {
		x=new Schedule(noOfRecords,name,date,staffName,time);
	}

	public void testWriteSchedule(){
		boolean result=Controller.writeSchedule(x);
		assertEquals(result, true);
	}
	
	public void testReadSchedule(){
		boolean result=Controller.readSchedule(name);
		assertEquals(result, true);
	}
	
	public void testGetReadScheduleResult(){
		Schedule data=null;
		if(Controller.readSchedule(name)){
			data=Controller.getReadScheduleResult();
		}
		assertEquals(data.getNoOfRecords(), x.getNoOfRecords());
		assertEquals(data.getName(),x.getName());
		assertEquals(data.getStartDate(),x.getStartDate());
		for(int i=0;i<noOfRecords;i++){
			assertEquals(data.getStaffName()[i],x.getStaffName()[i]);
			for(int j=0;j<Schedule.noOfDays;j++){
				assertEquals(data.getTime()[i][j],data.getTime()[i][j]);
			}
		}
	}
	
	public void testGetAllScheduleNames(){
		String[] list=Controller.getAllScheduleNames();
		for(int i=0;i<list.length;i++){
			System.out.println(list[i]);
		}
	}
	
	public void testDeleteSchedule(){
		Schedule tmp=new Schedule("toBeDeleted",123);
		assertEquals(Controller.writeSchedule(tmp),true);
		assertEquals(Controller.deleteSchedule(tmp),true);
	}
}